import React,{Component} from 'react';
import {FlatList,View,Text} from 'react-native';

export default class Demo23Component extends Component{
  constructor(){
    super();
    //初始化一个数组
    var tmpList=[];
    for(var i=0;i<15;i++){
      tmpList.push('test'+i)
    }
    //初始化状态
    this.state = {
      list:tmpList
    };
  }

  showListItem=(info)=>{
     return <Text>{info.item}</Text>
  }

  loadMore=()=>{
    //向this.state.list中插入5条数据
    var nowList = this.state.list;
    var length = nowList.length;
    for(var i=0;i<5;i++){
      var num = length+i;
      nowList.push('test'+num);
    }
    //设置状态
    this.setState({list:nowList});
  }

  render(){
    return <FlatList 
    onEndReached={this.loadMore}
    onEndReachedThreshold={0.5}
    renderItem={this.showListItem}
    data={this.state.list}></FlatList>
  }
}